from flask import Flask, render_template
from bokeh.resources import INLINE
from bokeh.embed import components
from picture import mpg, vbar_demo, Geographical_distribution
from jinja2 import Markup, Environment, FileSystemLoader
from pyecharts.globals import CurrentConfig
from random import randrange
from flask import Flask, render_template
from pyecharts import options as opts
from pyecharts.charts import Bar

app = Flask(__name__)

@app.route('/')
def index():
    return render_template('index.html')

@app.route('/vbar')
def vbar():
    p = vbar_demo()
    titles = ('#','Header','Header','Header','Header')
    # 表格数据准备
    contents = [['x',1, 2, 3, 4],['y',1.7, 2.2, 4.6, 3.9]]

    js_resources = INLINE.render_js()
    css_resources = INLINE.render_css()
    script, div = components(p)

    html = render_template(
        'vbar.html',
        plot_script=script,
        plot_div=div,
        js_resources=js_resources,
        css_resources=css_resources,
        the_titles=titles,
        the_contents=contents
    )
    return html



@app.route('/mpg')
def mpg_view():
    '''
    绘图模块picture -绘图函数 mpg
    '''
    p = mpg()

    js_resources = INLINE.render_js()
    css_resources = INLINE.render_css()
    script, div = components(p)

    html = render_template(
        'mpg.html',
        plot_script=script,
        plot_div=div,
        js_resources=js_resources,
        css_resources=css_resources
    )
    return html


@app.route('/fantime')
def fan_active():
    with open("粉丝活跃时间.html", encoding="utf8", mode="r") as f:
        plot_all = "".join(f.readlines())
    return render_template("fantime.html", the_plot_all = plot_all)

@app.route('/fanmap')
def fan_map():
    with open("粉丝分布地图.html", encoding="utf8", mode="r") as f:
        plot_all2 = "".join(f.readlines())
    return render_template("fanmap.html",the_plot_all2 = plot_all2)

@app.route('/fanfocus')
def fan_focus():
    with open("关注焦点.html", encoding="utf8", mode="r") as f:
        plot_all3 = "".join(f.readlines())
    return render_template("fanfocus.html",the_plot_all3 = plot_all3)

@app.route('/fantag')
def fan_tag():
    with open("粉丝人群标签.html", encoding="utf8", mode="r") as f:
        plot_all4 = "".join(f.readlines())
    return render_template("fantag.html",the_plot_all4 = plot_all4)


@app.route('/industryage')
def industry_age():
    with open("服饰年龄分布.html", encoding="utf8", mode="r") as f:
        plot_all5 = "".join(f.readlines())
    return render_template("industryage.html",the_plot_all5 = plot_all5)

@app.route('/hotnote')
def hot_note():
    with open("热门笔记.html", encoding="utf8", mode="r") as f:
        plot_all6 = "".join(f.readlines())
    return render_template("hotnote.html",the_plot_all6 = plot_all6)

@app.route('/shoucang')
def shou_cang():
    with open("收藏率.html", encoding="utf8", mode="r") as f:
        plot_all7 = "".join(f.readlines())
    return render_template("shoucang.html",the_plot_all7 = plot_all7)

if __name__ == '__main__':
    app.run()
